import React, {Component} from 'react';
import './index.less';
import {base} from 'nc-lightapp-front';
import getRosterData from "./functions/getRosterData";

const {NCTable} = base;

class RosterTable extends Component {
    constructor(props) {
        super(props);
        this.state = {
            columns: [],
            data: [],
            rptTitle:""
        };
        //this.getTableCom = this.getTableCom.bind(this);
        this.getTableCom(props);
    }

    // componentWillReceiveProps(nextProps) {
    //     this.getTableCom(nextProps);
    // }

    getTableCom() {
        getRosterData.call(this, (info) => {
            const columns = info.tableInfo.map(item => {
                return {
                    title: item.name, dataIndex: item.key, key: item.key, width: '120px'
                }
            });
            this.setState({
                columns,
                data: info.data,
                rptTitle : info.title
            });
        });
    }

    render() {
        const {columns, data,rptTitle} = this.state;
        return (
            <div>
                <div className='roster-title'>{rptTitle}</div>
                <div className='roster-table'>
                    {columns.length > 0 ? <NCTable
                        columns={columns}
                        data={data}
                        scroll={{x: true, y: true}}
                    /> : null}
                </div>
            </div>
        );
    }
}

export default RosterTable;
